
abstract class Animal {
    private String name;

    public Animal(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }


    public abstract void eat();

    public void sleep() {
        System.out.println(name + "正在睡觉");
    }
}


interface Afraid {
    void escape();
    void makeSounds();
}


class Dog extends Animal implements Afraid {
    public Dog(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println(getName() + "正在吃狗粮");
    }

    @Override
    public void escape() {
        System.out.println(getName() + "快速逃跑，尾巴夹着");
    }

    @Override
    public void makeSounds() {
        System.out.println(getName() + "发出害怕的呜咽声：呜呜呜...");
    }

    public void bark() {
        System.out.println(getName() + "汪汪叫！");
    }
}


class Cat extends Animal implements Afraid {
    public Cat(String name) {
        super(name);
    }

    @Override
    public void eat() {
        System.out.println(getName() + "正在吃猫粮");
    }

    @Override
    public void escape() {
        System.out.println(getName() + "跳起来哈气");
    }

    @Override
    public void makeSounds() {
        System.out.println(getName() + "发出害怕的嘶嘶声：hahahaha!!!!!哈气！！！");
    }

    public void meow() {
        System.out.println(getName() + "喵喵叫！");
    }
}


class Person {
    private String name;

    public Person(String name) {
        this.name = name;
    }


    public void feed(Animal animal) {
        System.out.println(name + "正在喂食" + animal.getName());
        animal.eat();
    }


    public void catchAnimal(Afraid afraidAnimal) {
        System.out.println(name + "试图接近");
        afraidAnimal.escape();
        afraidAnimal.makeSounds();
    }

    public void introduce() {
        System.out.println("我是" + name);
    }
}


public class Main {
    public static void main(String[] args) {
        Person person = new Person("小明");
        person.introduce();


        Animal myDog = new Dog("狗狗");
        Animal myCat = new Cat("猫猫");

        person.feed(myDog);
        person.feed(myCat);


        person.catchAnimal((Afraid) myDog);
        person.catchAnimal((Afraid) myCat);


        if (myDog instanceof Dog) {
            Dog realDog = (Dog) myDog;
            realDog.bark();
        }

        if (myCat instanceof Cat) {
            Cat realCat = (Cat) myCat;
            realCat.meow();
        }


        Animal[] animals = {new Dog("小黑"), new Cat("小白")};

        for (Animal animal : animals) {
            System.out.println("\n" + animal.getName() + "的行为：");
            animal.eat();
            animal.sleep();

            if (animal instanceof Afraid) {
                Afraid afraidAnimal = (Afraid) animal;
                afraidAnimal.escape();
                afraidAnimal.makeSounds();
            }
        }
    }
}